//
//  Custom3DView.m
//  AmountBody
//
//  Created by Qiu Jishuai on 2018/1/2.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

#import "CustomModelView.h"
#import "Masonry.h"
#import "CustomModelSwitchView.h"
#import "Customization.h"
#import "CustomConstants.h"

@interface CustomModelView()
@end

@implementation CustomModelView

- (void)setModel:(Customization *)model {
    _model = model;
    [_switchView setItems:model.models];
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
    }
    return self;
}

#pragma mark - Private Method
- (void)setupViews {
    self.modelView = [[UIImageView alloc] init];
    _modelView.image = [UIImage imageNamed:@"model"];
    [self addSubview: _modelView];

    self.switchView = [[CustomModelSwitchView alloc] init];
    _switchView.translatesAutoresizingMaskIntoConstraints = NO;
    [self addSubview: _switchView];
}

- (void)layoutSubviews {
    [super layoutSubviews];

    [_modelView mas_remakeConstraints:^(MASConstraintMaker *make) {
        layoutViews(^{ //横屏
            make.edges.equalTo(self).insets(UIEdgeInsetsMake(43, 148, 171, 56));
        }, ^{ //竖屏
            make.top.equalTo(self).offset(20);
            make.centerX.bottom.equalTo(self);
            make.width.equalTo(self).multipliedBy(0.36);
        });
    }];

    [_switchView mas_remakeConstraints:^(MASConstraintMaker *make) {
        layoutViews(^{ //横屏
            make.centerX.equalTo(_modelView);
            make.height.equalTo(@(kModelSwitchViewHeight));
            make.width.equalTo(@(kModelSwitchViewWidth));
            make.bottom.equalTo(self).offset(-65);
        }, ^{ //竖屏
            make.centerY.equalTo(self);
            make.right.equalTo(self).offset(-30);
            make.width.equalTo(@(kModelSwitchViewHeight));
            make.height.equalTo(@(kModelSwitchViewWidth));
        });
    }];
}

@end

